
let head = [1, 2, 6, 3, 4, 5, 6], val = 6
function ListNode(val, next) {
    this.val = (val === undefined ? 0 : val)
    this.next = (next === undefined ? null : next)
}
let list = new ListNode(head[0])
let num = list
for (let i = 1; i < head.length; i++) {
    num.next = new ListNode(head[i])
    num = num.next
};
var removeElements = function (head, val) {
    let dymhead = new ListNode()
    dymhead.next = head
    let cur = dymhead
    while (cur.next != null) {
        if (cur.next.val === val) {
            cur.next = cur.next.next
        } else {
            cur = cur.next
        }
    }
    return dymhead.next
};
console.log(removeElements(list, val));
